import mongoose from "mongoose";

const collegeInfoSchema = new mongoose.Schema(
  {
    name: { type: String, required: true },
    en_name: { type: String },
    rank: { type: Number },
    school_type: { type: String },
    location: { type: String },
    type: { type: String },
    score: { type: Number },
    coordinates: {
      lng: { type: Number },
      lat: { type: Number },
    },
    introduce: { type: String },
    historical_scores: {
      year_2024: { type: Number },
      year_2023: { type: Number },
      year_2022: { type: Number },
      year_2021: { type: Number },
    },
  },
  {
    timestamps: true,
  }
);

const collegeTypeSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    unique: true, // 确保类型名称唯一
    trim: true,
  },
});

collegeInfoSchema.index({ name: 1 });
collegeInfoSchema.index({ location: 1 });
collegeInfoSchema.index({ type: 1 });
collegeInfoSchema.index({ rank: 1 });
collegeInfoSchema.index({ school_type: 1 });
collegeInfoSchema.index({ "coordinates.lng": 1, "coordinates.lat": 1 });

export const CollegeType = mongoose.model("CollegeType", collegeTypeSchema);
export const CollegeInfo = mongoose.model("CollegeInfo", collegeInfoSchema);
